package data.structure.linear.queue;

import data.structure.linear.List;
import data.structure.linear.linkedList.SingleLinkedList;

/**
 * @Author douhy
 * @description 手写双端队列(链表实现)
 * @date 22/01/25
 */
public class Deque<E> {
    private List<E> list = new SingleLinkedList<E>();

    public int size() {
        return list.size();
    }

    public boolean isEmpty() {
        return list.isEmpty();
    }

    public void clear() {
        list.clear();
    }

    public void enQueueRear(E data) {
        list.add(data);
    }

    public E deQueueFront() {
        return list.remove(0);
    }

    public void enQueueFront(E data) {
        list.add(0,data);
    }

    public E deQueueRear() {
        return list.remove(list.size() - 1);
    }

    public E front(){
        return list.get(0);
    }

    public E rear(){
        return list.get(list.size() - 1);
    }
}
